// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   GDR.java

package jones.behavior;

import jones.SimpleRobotInterface;
import jones.ValueNotAvailableException;

// Referenced classes of package jones.behavior:
//            Behavior, Arbiter

public class GDR
    implements Behavior
{

    private static final String NAME = "GDR";
    private static final String IR = "IR";
    private static final String PHOTO = "Photo";
    private double a11 = 0;
    private double a12 = 0;
    private double a13 = 0;
    private double a21 = 0;
    private double a22 = 0;
    private double a23 = 0;
    private double a31 = 0;
    private double a32 = 0;
    private double a33 = 0;
    private String inputSensorType = null;

    public GDR()
    {
        a11 = 0.0D;
        a12 = 0.0D;
        a13 = 0.0D;
        a21 = 0.0D;
        a22 = 0.0D;
        a23 = 0.0D;
        a31 = 0.0D;
        a32 = 0.0D;
        a33 = 0.0D;
        inputSensorType = "Photo";
    }

    public GDR(String inputSensorType, double a11, double a12, double a13, 
            double a21, double a22, double a23, double a31, double a32, double a33)
    {
        this.a11 = 0.0D;
        this.a12 = 0.0D;
        this.a13 = 0.0D;
        this.a21 = 0.0D;
        this.a22 = 0.0D;
        this.a23 = 0.0D;
        this.a31 = 0.0D;
        this.a32 = 0.0D;
        this.a33 = 0.0D;
        this.inputSensorType = "Photo";
        setInputSensorType(inputSensorType);
        this.a11 = a11;
        this.a12 = a12;
        this.a13 = a13;
        this.a21 = a21;
        this.a22 = a22;
        this.a23 = a23;
        this.a31 = a31;
        this.a32 = a32;
        this.a33 = a33;
    }

    public String getName()
    {
        return "GDR";
    }

    public double getA11()
    {
        return a11;
    }

    public void setA11(double a11)
    {
        this.a11 = a11;
    }

    public double getA12()
    {
        return a12;
    }

    public void setA12(double a12)
    {
        this.a12 = a12;
    }

    public double getA13()
    {
        return a13;
    }

    public void setA13(double a13)
    {
        this.a13 = a13;
    }

    public double getA21()
    {
        return a21;
    }

    public void setA21(double a21)
    {
        this.a21 = a21;
    }

    public double getA22()
    {
        return a22;
    }

    public void setA22(double a22)
    {
        this.a22 = a22;
    }

    public double getA23()
    {
        return a23;
    }

    public void setA23(double a23)
    {
        this.a23 = a23;
    }

    public double getA31()
    {
        return a31;
    }

    public void setA31(double a31)
    {
        this.a31 = a31;
    }

    public double getA32()
    {
        return a32;
    }

    public void setA32(double a32)
    {
        this.a32 = a32;
    }

    public double getA33()
    {
        return a33;
    }

    public void setA33(double a33)
    {
        this.a33 = a33;
    }

    public String getInputSensorType()
    {
        return inputSensorType;
    }

    public void setInputSensorType(String inputSensorType)
    {
        if (!inputSensorType.equals("IR") && !inputSensorType.equals("Photo"))
        {
            throw new IllegalArgumentException("Input sensor type must be IR or Photo");
        } else
        {
            this.inputSensorType = inputSensorType;
            return;
        }
    }

    public void update(double d)
    {
    }

    public void act(Arbiter arbiter)
    {
        SimpleRobotInterface robot = (SimpleRobotInterface)arbiter.getRobotInterface(((Behavior) (this)));
        try
        {
            double left = 0.0D;
            double right = 0.0D;
            if (inputSensorType.equals("IR"))
            {
                if (robot.isLeftIROn())
                    left = 1.0D;
                if (robot.isRightIROn())
                    right = 1.0D;
            } else
            if (inputSensorType.equals("Photo"))
            {
                left = robot.getLeftPhoto();
                right = robot.getRightPhoto();
            } else
            {
                throw new RuntimeException("Unknown input sensor type: " + inputSensorType);
            }
            double translation = a11 * left + a21 * right + a31;
            double rotation = a12 * left + a22 * right + a32;
            double active = a13 * left + a23 * right + a33;
            if (active > 0.0D)
            {
                robot.setRotation(-rotation);
                robot.setTranslation(translation);
            }
        }
        catch (ValueNotAvailableException ex) { }
    }

    public String toString()
    {
        return "GDR";
    }
}
